<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>用key管理可复用的元素</title>
		<script src="https://cdn.jsdelivr.net/npm/vue"></script>
	</head>

	<body>
		<div id="app">
			<template v-if="loginType === 'username'">
				<label>Username</label>
				<input placeholder="Enter your username" key="username-input">
			</template>
			<template v-else>
				<label>Email</label>
				<input placeholder="Enter your email address" key="email-input">
			</template>
			<br/>
			<button @click="change()">Toggle login type</button>
		</div>
		<script>
			var vm = new Vue({
				el: '#app',
				data: {
					loginType: 'username',
					isshow: true
				},
				methods:{
					change:function(){
						if(this.isshow){
							this.loginType='username';
							this.isshow=false;
						}else{
							this.loginType='Email';
							this.isshow=true;
						}
					}
				}
			})
		</script>
	</body>

</html>